<?php
	
	require_once "dBConnect.php";
	session_start();
	$db = new dBConnect();
	// get primary key
	$oldEmail = $_SESSION['email'];
	
	//retrieve form data
//	$email = $_POST['email'];
	$email = $oldEmail;
	$firstname = $_POST['firstname'];
	$lastname = $_POST['lastname'];
	$teams[] = $_POST['teams'];
	
//	print_r($teams);
	
	$db->remove("email='$oldEmail'", "team_members");
	
	foreach ($teams[0] as $teamid) {
//		echo $teamid." ".$email;
		$db->insert("'$teamid', '$email'", "team_members");
	}
		
//	$db->update("users", "email='$email'", "email='$oldEmail'");
	$db->update("team_members", "email='$email'", "email='$oldEmail'");
	$db->update("users", "firstname='$firstname'", "email='$oldEmail'");
	$db->update("users", "lastname='$lastname'", "email='$oldEmail'");

	header("location:viewMonth.php");
?>